package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.ActivitiesRegistrationParam;
import com.macro.mall.dto.ActivitiesRegistrationResult;
import com.macro.mall.dto.BmsTourismProjectActivitiesApplicantDetail;
import com.macro.mall.dto.BmsTourismProjectActivitiesApplicantParam;
import com.macro.mall.model.BmsTourismProjectActivitiesApplicant;
import com.macro.mall.portal.service.BmsTourismProjectActivitiesApplicantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@Api(tags = "BmsTourismProjectActivitiesApplicantController")
@Tag(name = "BmsTourismProjectActivitiesApplicantController", description = "文旅项目-活动")
@RequestMapping("/tourismProjectActivitiesApplicant")
public class BmsTourismProjectActivitiesApplicantController {

    @Autowired
    private BmsTourismProjectActivitiesApplicantService bmsTourismProjectActivitiesApplicantService;

    @ApiOperation("分页查询文旅项目-活动")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsTourismProjectActivitiesApplicant>> getList(@RequestBody BmsTourismProjectActivitiesApplicantParam bmsTourismProjectActivitiesApplicantParam) {
        List<BmsTourismProjectActivitiesApplicant> bmsTourismProjectActivitiesApplicantList = bmsTourismProjectActivitiesApplicantService.getList(bmsTourismProjectActivitiesApplicantParam);
        return CommonResult.success(CommonPage.restPage(bmsTourismProjectActivitiesApplicantList));
    }

    @ApiOperation("根据id获取文旅项目-活动信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsTourismProjectActivitiesApplicantDetail> getItem(@PathVariable Long id) {
        BmsTourismProjectActivitiesApplicantDetail bmsTourismProjectActivitiesApplicantDetail = bmsTourismProjectActivitiesApplicantService.getItem(id);
        return CommonResult.success(bmsTourismProjectActivitiesApplicantDetail);
    }

    @ApiOperation("活动预约报名")
    @RequestMapping(value = "/activitiesRegistration", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<String> reservationRegistration(@RequestBody ActivitiesRegistrationParam activitiesRegistrationParam) {
        ActivitiesRegistrationResult activitiesRegistrationResult = bmsTourismProjectActivitiesApplicantService.activitiesRegistration(activitiesRegistrationParam);
        if (activitiesRegistrationResult.getCode().equals("500")) {
            return CommonResult.failed(activitiesRegistrationResult.getMessage());
        }
        return CommonResult.success(activitiesRegistrationResult.getMessage());
    }

    @ApiOperation("活动预约报名")
    @RequestMapping(value = "/activitiesCancel", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<String> activitiesCancel(@RequestBody ActivitiesRegistrationParam activitiesRegistrationParam) {
        ActivitiesRegistrationResult activitiesRegistrationResult = bmsTourismProjectActivitiesApplicantService.activitiesCancel(activitiesRegistrationParam);
        if (activitiesRegistrationResult.getCode().equals("500")) {
            return CommonResult.failed(activitiesRegistrationResult.getMessage());
        }
        return CommonResult.success(activitiesRegistrationResult.getMessage());
    }


    @ApiOperation("活动状态修改")
    @RequestMapping(value = "/handleRegistrationStatus", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> handleRegistrationStatus(@RequestParam("status")String status, @RequestParam("tourismProjectActivitiesId") String tourismProjectActivitiesId, HttpServletRequest request) {
        bmsTourismProjectActivitiesApplicantService.handleRegistrationStatus(tourismProjectActivitiesId, status);
        return CommonResult.success("");
    }


}
